<?php

    class activities extends CI_Controller {
        function __construct(){
            parent::__construct();
            $this->load->model('activities_model');
        }

        function index($page = 1, $per_page = 20) {
            $act = $this->activities_model->lists($page, $per_page);
            $this->data['rows'] = $act['rows'];
            $this->data['total'] = $act['total'];
            $this->load->view('activities/index.php', $this->data);
        }

        function add() {
            if (!$this->input->post()) {
                $this->load->view('/activities/add.php');
            } else {
                $name = $this->input->post('name');
                $date = $this->input->post('date');
                $sponsor = $this->input->post('sponsor');
                $description = $this->input->post('description');
                $totalmoney = $this->input->post('totalmondy');

                $data = array(
                    'name' => $name,
                    'date' => $date,
                    'sponsor' => $sponsor,
                    'description' => $description,
                    'todalmoney' => $totalmoney
                );
                $this->activities_model->add($data);
                redirect(base_url('/activities'));
            }
        }

        function edit($id) {
            if (!$this->input->post()) {
                $activities = $this->activities_model->get($id);
                $this->data['data'] = $activities[0];
                $this->load->view('activities/edit.php', $this->data);
            } else {
                $name = $this->input->post('name');
                $date = $this->input->post('date');
                $sponsor = $this->input->post('sponsor');
                $description = $this->input->post('description');
                $totalmoney = $this->input->post('totalmoney');

                $data = array(
                    'name' => $name,
                    'date' => $date,
                    'sponsor' => $sponsor,
                    'description' => $description,
                    'todalmoney' => $totalmoney
                );
                $this->activities_model->update($id, $data);
                redirect(base_url('/activities'));
            }
        }

        function delete($id) {
            $this->activities_model->delete($id);
        }
    }
?>